<template>
  <div class="col_form office_first">
    <div class="input_wrapper">
      <div class="flex name">
        <label class="flex align-center justify-center"><span class="required-icon">*</span>主标题</label>
        <el-input v-model="formData.main_title" placeholder="请输入主标题" clearable />
      </div>
    </div>
    <goods-add :max-num="goodsNum" :goods-list="formData.goods" @setGoods="setGoods" />
  </div>
</template>

<script>
import goodsAdd from './goodsAdd'
export default {
  components: { goodsAdd },
  // props: ['goodsNum', 'levelName'],
  props: {
    goodsNum: {
      type: String,
      default: ''
    },
    levelName: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      formData: {
        main_title: '',
        goods: []
      }
    }
  },
  methods: {
    setGoods(list) {
      this.formData.goods = list
    },
    save() {
      if (!this.formData.main_title) {
        this.$message({
          message: '主标题不能为空',
          type: 'error'
        })
        return false
      }
      let goodsidStr = ''
      if (this.formData.goods.length > 0) {
        goodsidStr += this.formData.goods.map(k => k.goods_id).join(',')
      }
      return {
        level: this.levelName,
        main_title: this.formData.main_title,
        goodsidStr
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.office_first {
  .input_wrapper {
    margin-top: 10px;
    margin-left: 0;

    &>div {
      label {
        width: 90px;
      }
    }
  }
}
</style>
